﻿using System;
using System.Collections.Generic;
using UnityEngine.U2D;
/// <summary>
/// AssetBundle资源管理器
/// </summary>
public partial class ESF_ABMgr
{
    /// <summary>
    /// 加载资源到内存
    /// </summary>
    /// <param name="_abPathAttr">资源路径属性</param>
    /// <param name="_onSuccess">成功</param>
    /// <param name="_onFailed">失败</param>
    /// <param name="_onCancel">取消</param>
    /// <param name="_onProgress">进度</param>
    /// <param name="_extralArgs">额外参数</param>
    /// <returns>任务</returns>
    public delegate AbsESF_Task ESF_AssetBundleLoadInMemoryFunc(
        ESF_AssetBundlePathAttribute _abPathAttr,
        Action<AbsESF_AssetResponse, object[]> _onSuccess,
        Action<AbsESF_AssetResponse, object[]> _onFailed,
        Action<AbsESF_AssetResponse, object[]> _onCancel,
        Action<AbsESF_AssetResponse, object[]> _onProgress,
        Action<AbsESF_AssetResponse, object[]> _onWaitDownloadResponse,
        params object[] _extralArgs
            );

    /// <summary>
    /// 加载资源到内存
    /// </summary>
    /// <param name="_abPathAttr">资源路径属性</param>
    /// <param name="_onSuccess">成功</param>
    /// <param name="_onFailed">失败</param>
    /// <param name="_onCancel">取消</param>
    /// <param name="_onWaitDownload">等待下载</param>
    /// <param name="_onProgress">进度</param>
    /// <param name="_extralArgs">额外参数</param>
    /// <returns>任务</returns>
    public AbsESF_Task LoadInMemory(ESF_AssetBundlePathAttribute _abPathAttr, 
        Action<AbsESF_AssetResponse, object[]> _onSuccess,
        Action<AbsESF_AssetResponse, object[]> _onFailed,
        Action<AbsESF_AssetResponse, object[]> _onCancel,
        Action<AbsESF_AssetResponse, object[]> _onProgress,
        Action<AbsESF_AssetResponse, object[]> _onWaitDownloadResponse,
        params object[] _extralArgs)
    {
        return OnLoadInMemory(_abPathAttr, _onSuccess, _onFailed, _onCancel, _onProgress, _onWaitDownloadResponse,_extralArgs);
    }

    /// <summary>
    /// 加载资源到内存
    /// </summary>
    /// <param name="_abPathAttr">资源路径属性</param>
    /// <param name="_onSuccess">成功</param>
    /// <param name="_onFailed">失败</param>
    /// <param name="_onCancel">取消</param>
    /// <param name="_onWaitDownload">等待下载</param>
    /// <param name="_onProgress">进度</param>
    /// <param name="_extralArgs">额外参数</param>
    /// <returns>任务</returns>
    public AbsESF_Task OnLoadInMemory(ESF_AssetBundlePathAttribute _abPathAttr,
        Action<AbsESF_AssetResponse, object[]> _onSuccess,
        Action<AbsESF_AssetResponse, object[]> _onFailed,
        Action<AbsESF_AssetResponse, object[]> _onCancel,
        Action<AbsESF_AssetResponse,object[]> _onProgress,
        Action<AbsESF_AssetResponse, object[]> _onWaitDownload,
        params object[] _extralArgs)
    {
        AbsESF_Task task = new ESF_DefaultTask();
        OnReadAssetBundleManifest(() => {
            OnCheckAssetBundlePathAttributeLanguage(_abPathAttr);
            ESF_AssetRequest assetResult = new ESF_AssetRequest(_abPathAttr, task, _onSuccess, _onFailed, _onCancel, _onProgress, _onWaitDownload, _extralArgs);

            OnStartLoad(assetResult);
        });
      
        return task;
    }
}
